package com.caicai.user;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import cmo.caicai.service.UserInfoService;

import com.caicai.domain.User;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.IntStream;

@RestController
@RequestMapping(value = "/user")
public class UserController {
	@Autowired
	UserInfoService userInfoService;

	@RequestMapping(method=RequestMethod.GET)
	public String getUserInfo(){

		User user=new User();
		user.setId("1");
		user.setName("张三");
		user.setSex("男");
		Object saveUser=userInfoService.save(user);
		return "111";
	}

	@RequestMapping(value = "/list",method=RequestMethod.GET)
	public String saveUserInfo(){
		List<User> users=new ArrayList<>();
		IntStream.range(0,2).forEach((i)->{
			User user=new User();
			user.setId(i+"");
			user.setName("张三"+i);
			user.setSex("男");
			users.add(user);
		});
		Object saveUser=userInfoService.saveList(users);
		return "111";
	}


	@RequestMapping(value = "/{id}",method=RequestMethod.GET)
	public User findUserById(@PathVariable String id){
		return userInfoService.findById(id);
	}


	@RequestMapping(value = "/test01/{id}",method=RequestMethod.GET)
	public User test01(@PathVariable String id){
		return userInfoService.findById(id);
	}


	@RequestMapping(value = "/test02/{id}",method=RequestMethod.GET)
	public User test02(@PathVariable String id){
		return userInfoService.findById(id);
	}


	@RequestMapping(value = "/test03",method=RequestMethod.GET)
	public void test011(){
		System.out.println("进入无参");

	}


}
